﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TanHuan.Authorize.Biz;
using TanHuan.Authorize.Model;
using TanHuan.Authorize.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace TanHuan.Authorize.Web.Controllers
{
    public class AuthAppController : Controller
    {
        AuthAppBiz aaBiz = new AuthAppBiz();

        //
        // GET: /AuthApp/

        public ActionResult Index()
        {
            return View();
        }

        public string GetAuthApp()
        {
            PageItem pItem = new PageItem();
            pItem.Size = int.Parse(Request.Form["rows"]);
            pItem.Index = int.Parse(Request.Form["page"]);
            pItem.Order = Request.Form["order"];
            pItem.Sort = Request.Form["sort"];
            string jsonStr = DataToJson.GetGridJson(aaBiz.GetAuthApp(pItem), pItem);
            return jsonStr;
        }

        public ActionResult CreateAuthApp()
        {
            AuthApp entity = new AuthApp();
            entity.AppId = Request.Form["AppId"];
            entity.AppName = Request.Form["AppName"];
            entity.AppStatus = int.Parse(Request.Form["AppStatus"]);
            entity.Memo = Request.Form["Memo"];
            entity.ModifyUser = "谭欢";
            aaBiz.CreateAuthApp(entity);
            return View();
        }

        public ActionResult EditAuthApp(int unid)
        {
            AuthApp entity = new AuthApp();
            entity.Unid = unid;
            entity.AppId = Request.Form["AppId"];
            entity.AppName = Request.Form["AppName"];
            entity.AppStatus = int.Parse(Request.Form["AppStatus"]);
            entity.Memo = Request.Form["Memo"];
            entity.ModifyUser = "谭欢";
            aaBiz.EditAuthApp(entity);
            return View();
        }

        public ActionResult DeleteAuthApp(int unid)
        {
            aaBiz.DeleteAuthApp(unid);
            return Json("删除成功！");
        }
    }
}
